package com.polaris.live.ui.user_space

import android.animation.ObjectAnimator
import android.animation.PropertyValuesHolder
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.animation.LinearInterpolator
import androidx.core.animation.addListener
import androidx.core.widget.NestedScrollView.OnScrollChangeListener
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.StringUtils
import com.blankj.utilcode.util.UriUtils
import com.lxj.xpopup.XPopup
import com.polaris.live.R
import com.polaris.live.adapter.user_space.UserSpaceGiftAdapter
import com.polaris.live.adapter.user_space.UserSpaceLabelAdapter
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.common.constant.AppConst
import com.polaris.live.common.constant.CommonConst
import com.polaris.live.common.constant.PagConst.LIKE_AFTER_ANIM_PAG
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.mvvm.base2.BaseVbActivity
import com.polaris.live.common.network.AppException
import com.polaris.live.common.network.parseState
import com.polaris.live.common.util.JsonUtils
import com.polaris.live.common.util.NavigationBarUtils
import com.polaris.live.common.util.ToastGravity
import com.polaris.live.constant.LiveConst
import com.polaris.live.constant.UserConst
import com.polaris.live.databinding.ActivitySpaceBinding
import com.polaris.live.dialog.GlobalDialogManager
import com.polaris.live.dialog_fragment.GiftDialogFragment
import com.polaris.live.im.manager.ImManager
import com.polaris.live.im.sfs.COMMAND_SINGLE_MESSAGE
import com.polaris.live.im.sfs.TYPE_MESSAGE_GIFT
import com.polaris.live.im.sfs.bean.chat.SingleMessage
import com.polaris.live.im.sfs.bean.chat.ext.SingleMessageExtBean
import com.polaris.live.im.sfs.bean.chat.ext.SingleMessagePayloadBean
import com.polaris.live.im.sfs.bean.live.ext.UserBasicVo
import com.polaris.live.interface_bag.PAGListener
import com.polaris.live.interface_bag.PAGViewListener
import com.polaris.live.manager.LiveStateManager
import com.polaris.live.popup.GlobalPopupManager
import com.polaris.live.popup.RemarkPopup
import com.polaris.live.popup.UserSpaceMorePopup
import com.polaris.live.popup.UserSpaceMorePopup.Companion.blocak
import com.polaris.live.popup.UserSpaceMorePopup.Companion.followe
import com.polaris.live.resp.back_resp.InfoOtherResp
import com.polaris.live.resp.back_resp.UserNumberExt
import com.polaris.live.resp.back_resp.UserOtherRemarkVo
import com.polaris.live.resp.back_resp.toUserBasicVo
import com.polaris.live.translation.R.string
import com.polaris.live.ui.me.RichCharmActivity
import com.polaris.live.ui.user_space.proxy.UserSpaceUiChangeProxy
import com.polaris.live.utils.LiveUtils
import com.polaris.live.utils.OtherUserCacheUtils
import com.polaris.live.utils.StartCallProxy
import com.polaris.live.utils.getIntOrString
import com.polaris.live.utils.getLongOrString
import com.polaris.live.utils.route.RoutePath
import com.polaris.live.utils.route.Router
import com.polaris.live.viewmodel.UserSpaceViewModel
import com.polaris.live.widget.pag.AddFollowView.Companion.LIVE_ADD_FOLLOWE_ALPHA
import com.yalantis.ucrop.UCrop
import org.libpag.PAGImageView
import org.libpag.PAGView

/**
 *
 *UserSpaceActivity
 * @author Created by 半仙 on 2023/9/22/022 14:08
 */
class UserSpaceActivity : BaseVbActivity<UserSpaceViewModel, ActivitySpaceBinding>() {

    private val mOtherId: Long by lazy { intent.getLongOrString("userId", 0L) }
    private val userBasicVo: UserBasicVo? by lazy {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            intent.getParcelableExtra("userBasic", UserBasicVo::class.java)
        } else {
            intent.getParcelableExtra("userBasic")
        }
    }
    private val mPage: Int by lazy { intent.getIntOrString("page", UserConst.From.UNKNOWN) }

    private var mOtherInfo: InfoOtherResp? = null

    private lateinit var mUIProxy: UserSpaceUiChangeProxy
//    private lateinit var mUserStateProxy: UserStatePlayerProxy<UserSpaceViewModel>

    private val mGiftAdapter by lazy { UserSpaceGiftAdapter() }
    private val mLabelAdapter by lazy { UserSpaceLabelAdapter() }

    private var mTitleAlpha = 0.0F

    private var mIsLiked = false

    private var mute: Boolean = false //是否禁言
    private var ban: Boolean = false  //是否封号


    override fun initImmersionBar() {
        val lp = mBinding.titleBack.layoutParams
        if (lp is ViewGroup.LayoutParams) {
            lp.height =
                resources.getDimension(R.dimen.bar_height).toInt() + BarUtils.getStatusBarHeight()
            mBinding.titleBack.layoutParams = lp
        }
        NavigationBarUtils.setImmersionBarForUserSpace(this)
    }

    private val mGiftDialog: GiftDialogFragment
        get() = GiftDialogFragment(
            showType = AppConst.GiftComming.SINGLE,
            AppConst.BackpackGiftComming.MESSAGE,
            null,
            false,
            sendGiftCallback = { giftSendBean ->
                mOtherInfo?.userId?.let { it1 ->
                    showLoading(waitTime = 0)

                    val singleMessage = SingleMessage(
                        recipient = it1,
                        content = giftSendBean.gift.id.toString(),
                        type = TYPE_MESSAGE_GIFT,
                        payload = JsonUtils.toJson(
                            SingleMessagePayloadBean(
                                giftAmount = giftSendBean.num,
                                giftBackpackId = giftSendBean.backpackId,
                                payload = giftSendBean.gift.payload
                            )
                        ),
                        ext = JsonUtils.toJson(
                            SingleMessageExtBean(
                                giftName = giftSendBean.gift.giftName,
                                giftUrl = giftSendBean.gift.pic,
                            )
                        )
                    )

                    ImManager.sendMessageWithAsync(
                        this,
                        COMMAND_SINGLE_MESSAGE,
                        singleMessage,
                        onCompleted = {
                            if (it is AppException) {
                                if (it.errCode == CommonConst.ErrorCode.VIP_LEVEL_INSUFFICIENT) {
                                    GlobalDialogManager.showInsufficientVIPLevel(
                                        this,
                                        giftSendBean.gift.payload,
                                        giftSendBean.gift.pic
                                    )
                                }
                            }
                            if (it == null) {
                                mBinding.contributorsView.update()
                                ToastGravity.showGravity(StringUtils.getString(string.send_gift_success))
                            }
                            dismissLoading()
                        }
                    )
                }
            })

    override fun initView(savedInstanceState: Bundle?) {
        mBinding.followImg.apply {
            setPathType(LIVE_ADD_FOLLOWE_ALPHA)
            addListener(object : PAGViewListener {
                override fun onAnimationEnd(p0: PAGView?) {
                    super.onAnimationEnd(p0)
                    mBinding.followImg.visibility = View.INVISIBLE
                }
            })
            setRepeatCount(1)
        }

        mViewModel.getInfoUser(mOtherId)

        if (mOtherId == UserManager.getUserId()) {
            mBinding.contributorsView.initView(mOtherId, mViewModel)
        }

        mUIProxy = UserSpaceUiChangeProxy(this, mViewModel, mBinding, mGiftAdapter, mLabelAdapter)

//        mUserStateProxy = UserStatePlayerProxy(
//            this,
//            mViewModel,
//            mOtherId,
//            LiveActivityIdentifier.USER_SPACE_ACTIVITY
//        )

//        mBinding.video.outlineProvider =
//            TextureVideoViewOutlineProvider(ConvertUtils.dp2px(4f).toFloat())
//        mBinding.video.clipToOutline = true

        initObserver()
        initListener()

        setCache()
    }

    /**
     * 设置缓存数据
     */
    private fun setCache() {
        val otherInfo = OtherUserCacheUtils[mOtherId].apply {
            mOtherInfo = this
        }
        if (otherInfo == null) {
            showLoading(hasShadowBg = true, waitTime = 0)
            userBasicVo?.let {
                mUIProxy.uiInitBasic(it)
            }
        } else {
            mUIProxy.uiInit(otherInfo)
            mIsLiked = otherInfo.relation?.liked ?: false
        }
    }

    private fun initListener() {
        scrollChange()
        mBinding.icBack.setOnSingleClickListener {
            finish()
        }

        mBinding.llCharm.setOnSingleClickListener {
            if (isSelf()) {
                Router.instance.setPath(RoutePath.RICH_CHARM_ACTIVITY)
                    .withInt(RichCharmActivity.PAGE, 1).navigation(this)
            }
        }

        mBinding.tvComeIn.setOnSingleClickListener {
            mOtherInfo?.let { it1 -> LiveUtils.invokeSpectator(this, it1) }
        }

        mBinding.llRich.setOnSingleClickListener {
            if (isSelf()) {
                Router.instance.setPath(RoutePath.RICH_CHARM_ACTIVITY)
                    .withInt(RichCharmActivity.PAGE, 0).navigation(this)
            }
        }

        //去礼物列表
        mBinding.llGiftTitle.setOnSingleClickListener {
            mOtherInfo?.userId?.let { it1 ->
                Router.instance.setPath(RoutePath.GIFT_LIST_ACTIVITY)
                    .withLong(CommonConst.Gift.USER_ID, it1)
                    .navigation(this)
            }
        }

        //去私信
        mBinding.goMessage.setOnSingleClickListener {
            mOtherInfo?.userId?.let { userId ->
                Router.instance.setPath(RoutePath.MESSAGE_ACTIVITY)
                    .withInt("page", mPage)
                    .apply {
                        mOtherInfo?.also {
                            withString("nickname", it.nickname)
                            withString("avatar", it.avatar)
                            it.decoration?.avatarFrame?.also { af -> withString("avatarFrame", af) }
                            it.decoration?.chatBubble?.also { cb -> withString("chatBubble", cb) }
                        }
                    }
                    .withLong("userId", userId)
                    .navigation(this)
            }
        }
        //送礼物
        mBinding.sendGift.setOnSingleClickListener {
            mGiftDialog.apply {
                mOtherInfo?.userId?.let { setUserId(it, mOtherInfo?.nickname) }
                show(supportFragmentManager, GiftDialogFragment.FRAGMENT_TAG)
            }
        }
        //拨打电话
        mBinding.goCall.setOnSingleClickListener {
            if (LiveStateManager.isLiving()) {
                ToastGravity.showGravity(StringUtils.getString(string.call_fail_place_close_live))
                return@setOnSingleClickListener
            }
            mOtherInfo?.userId?.let { id ->
                StartCallProxy.builder(this).startCall(
                    mViewModel,
                    mPage,
                    UserConst.LastFrom.OTHER_SPACE,
                    LiveConst.SenderFrom.MANUAL,
                    id,
                    mOtherInfo?.toUserBasicVo()
                )
            }
        }
        mBinding.freeMatch.setOnSingleClickListener {
            if (LiveStateManager.isLiving()) {
                ToastGravity.showGravity(StringUtils.getString(string.call_fail_place_close_live))
                return@setOnSingleClickListener
            }

            mOtherInfo?.userId?.let { id ->
                StartCallProxy.builder(this).startCall(
                    mViewModel,
                    mPage,
                    UserConst.LastFrom.OTHER_SPACE,
                    LiveConst.SenderFrom.MANUAL,
                    id,
                    mOtherInfo?.toUserBasicVo()
                )
            }
        }
        //关注
        mBinding.followImg.setOnSingleClickListener {
            mOtherInfo?.userId?.let { it1 ->
                mViewModel.addFollower(it1)
            }
        }
        //更多
        mBinding.icMore.setOnSingleClickListener {
            if (!isSelf()) {
                val map = mutableMapOf<String, Boolean>()
                mOtherInfo?.relation?.blocked?.let { it1 -> map.put(blocak, it1) }
                mOtherInfo?.relation?.followed?.let { it1 -> map.put(followe, it1) }

                val nickname = mOtherInfo?.nickname ?: ""
                val id = mOtherInfo?.userId
                val block = mOtherInfo?.relation?.blocked ?: false

                XPopup.Builder(this)
                    .isDestroyOnDismiss(true)
                    .asCustom(UserSpaceMorePopup(this, mViewModel, mOtherId, mute, ban, map, {
                    when (it) {
                            UserSpaceMorePopup.BLACK -> {
                                if (id != null) {
                                    GlobalDialogManager.showBlackIt(
                                        this,
                                        mViewModel,
                                        block,
                                        nickname,
                                        id
                                    ) { black ->
                                        if (black) {
                                            mBinding.followImg.visibility = View.VISIBLE
                                            mOtherInfo?.relation?.followed = false
                                            //拉黑移出緩存
                                            OtherUserCacheUtils.removeUser(id)
                                        }
                                        mOtherInfo?.relation?.blocked = black
                                    }
                                }
                            }

                            UserSpaceMorePopup.FOLLOWE -> {
                                if (id != null) {
                                    mOtherInfo?.relation?.followed?.let { it1 ->
                                        GlobalDialogManager.followOther(
                                            mViewModel,
                                            id,
                                            it1
                                        ) { follow ->
                                            if (follow) {
                                                mBinding.followImg.visibility = View.INVISIBLE
                                            } else {
                                                mBinding.followImg.visibility = View.VISIBLE
                                            }
                                            mOtherInfo?.relation?.followed = follow
                                        }
                                    }
                                }
                            }

                            UserSpaceMorePopup.REPORT -> {
                                if (id != null) {
                                    GlobalPopupManager.showReport(
                                        this, nickname,
                                        mViewModel, id
                                    )
                                }
                            }
                        }
                    }, {
                        mute = it
                    }, {
                        Router.instance.setPath(RoutePath.SEAL_ACCOUNT_ACTIVITY)
                            .withLong("userId", mOtherInfo?.userNumber ?: 0L)
                            .withLong("otherId", mOtherId)
                            .navigation(this)
                        finish()
                    }))
                    .show()

            } else {
                Router.instance.setPath(RoutePath.INFO_USER_ACTIVITY)
                    .navigation(this)
            }
        }
        //备注
        mBinding.reMakeLl.setOnSingleClickListener {
            XPopup.Builder(this)
                .isDestroyOnDismiss(true)
                .asCustom(
                    RemarkPopup(
                        this,
                        mOtherInfo?.remark?.remark ?: ""
                    ) { isEdit, remark ->
                        mOtherInfo?.userId?.let {
                            if (isEdit) {
                                mViewModel.putRemark(it, remark)
                            } else {
                                mViewModel.addRemark(it, remark)
                            }
                        }
                    }
                )
                .show()
        }
        //点赞
        mBinding.addLike.setOnSingleClickListener {
            if (!mIsLiked) {
                mOtherInfo?.userId?.let { it1 -> mViewModel.addLike(it1) }
            }
        }
        //点击视频流
//        mBinding.videoCard.setOnSingleClickListener {
//            if (LiveStateManager.isLiving()) {
//                ToastGravity.showGravity(StringUtils.getString(string.place_close_live))
//                return@setOnSingleClickListener
//            }
//            if (mOtherInfo?.relation?.blocked == true) {
//                ToastGravity.showGravity(StringUtils.getString(string.no_access))
//                return@setOnSingleClickListener
//            }
//            GlobalPopupManager.showCompletePopup(this) {
//                val userInfo = mOtherInfo
//                if (userInfo != null) {
//                    if (userInfo.live?.liveType == LiveConst.Type.ONLY_LIVE) {
//                        LiveUtils.toSpectator(userInfo).navigation(this)
//                    } else {
//                        StartCallProxy.builder(this).startCall(
//                            mViewModel,
//                            mPage,
//                            UserConst.LastFrom.OTHER_SPACE,
//                            LiveConst.SenderFrom.MANUAL,
//                            userInfo.userId,
//                            userInfo.toUserBasicVo()
//                        )
//                    }
//                }
//            }
//        }
        //点击头像
        mBinding.relTitle.setOnSingleClickListener {
            val isGoInfo =
                mOtherInfo?.userId == UserManager.getUserId() && UserManager.getUser().avatarModified == AppConst.NO
            if (isGoInfo) {
                Router.instance.setPath(RoutePath.INFO_USER_ACTIVITY)
                    .navigation(this)
            }
        }
    }

    private fun scrollChange() {
        mBinding.scroll.setOnScrollChangeListener(OnScrollChangeListener { v, _, scrollY, _, oldScrollY ->
            if (scrollY > oldScrollY) {//向下滚动
                mTitleAlpha += 0.05f
                if (mTitleAlpha >= 1.0) {
                    mTitleAlpha = 1.0f
                }
            }

            if (scrollY < oldScrollY) {//向上滚动
                mTitleAlpha -= 0.05f

                if (mTitleAlpha <= 0.0) {
                    mTitleAlpha = 0.0f
                }
            }

            if (scrollY == 0) {// 滚动到顶
                mTitleAlpha = 0.0f
                setAlpha()
            }
            // 滚动到底`
            if (scrollY == (v.getChildAt(0).measuredHeight - v.measuredHeight)) {
                mTitleAlpha = 1.0f
                setAlpha()
            }
            setAlpha()
        })
    }

    private fun setAlpha() {
        mBinding.titleBack.alpha = mTitleAlpha
        mBinding.titleNickName.alpha = mTitleAlpha

        if (mTitleAlpha > 0.5) {
            mBinding.icBack.setImageResource(R.drawable.ic_arrow_back_black)
        } else {
            mBinding.icBack.setImageResource(R.drawable.ic_arrow_back_white)
        }

        if (isSelf()) {
            if (mTitleAlpha > 0.5) {
                mBinding.icMore.setImageResource(R.drawable.ic_edit_black)
            } else {
                mBinding.icMore.setImageResource(R.drawable.ic_edit)
            }
        } else {
            if (mTitleAlpha > 0.5) {
                mBinding.icMore.setImageResource(R.drawable.ic_more_black)
            } else {
                mBinding.icMore.setImageResource(R.drawable.ic_more_white)
            }
        }
    }

    private fun initObserver() {
        mViewModel.infoLiveData.observe(this) { resultState ->
            parseState(resultState, {
                OtherUserCacheUtils.addUser(it, true)
                mUIProxy.uiInit(it)
                mOtherInfo = it

                mIsLiked = it.relation?.liked ?: false
                mute = it.flag.mute
//                mUserStateProxy.init(it, mBinding.videoCard, mBinding.video)
            }, {
                when (it.errCode) {
                    CommonConst.ErrorCode.USER_LOGGED_OUT -> {//用户已注销
                        OtherUserCacheUtils.removeUser(mOtherId)
                        val ext = JsonUtils.fromJson<UserNumberExt>(JsonUtils.toJson(it.ext))
                        Router.instance.setPath(RoutePath.SIGN_OUT_ACTIVITY)
                            .withLong("userId", ext?.userNumber ?: 0L).navigation(this)
                        finish()
                    }

                    CommonConst.ErrorCode.ACCOUNT_SHUT_DOWN -> {//该账号已经被关小黑屋

                        OtherUserCacheUtils.removeUser(mOtherId)
                        val ext = JsonUtils.fromJson<UserNumberExt>(JsonUtils.toJson(it.ext))
                        Router.instance.setPath(RoutePath.SEAL_ACCOUNT_ACTIVITY)
                            .withLong("userId", ext?.userNumber ?: 0L)
                            .withLong("otherId", mOtherId)
                            .navigation(this)
                        finish()
                    }

                    CommonConst.ErrorCode.YOU_BLOCKED_OTHER -> { //你拉黑对方
                        ToastGravity.showGravity(StringUtils.getString(string.no_access))
                        finish()
                    }

                    CommonConst.ErrorCode.OTHER_BLOCKED_YOU -> { //对方拉黑你
                        ToastGravity.showGravity(StringUtils.getString(string.other_blocked_you))
                        finish()
                    }

                    else -> {
                        ToastGravity.showGravity(it.errorMsg)
                    }
                }
            })
        }
        mViewModel.infoFlushLiveData.observe(this) { resultState ->
            parseState(resultState, {
                OtherUserCacheUtils.addUser(it, true)
                mOtherInfo = it
                if (it.relation?.followed == true || isSelf()) {
                    mBinding.followImg.visibility = View.GONE
                } else {
                    mBinding.followImg.visibility = View.VISIBLE
                }
                if (this::mUIProxy.isInitialized) {
                    mUIProxy.onResumeData(it)
                }
            }, {
                when (it.errCode) {
                    CommonConst.ErrorCode.USER_LOGGED_OUT -> {//用户已注销
                        val ext = JsonUtils.fromJson<UserNumberExt>(JsonUtils.toJson(it.ext))
                        Router.instance.setPath(RoutePath.SIGN_OUT_ACTIVITY)
                            .withLong("userId", ext?.userNumber ?: 0L)
                            .navigation(this)
                    }

                    CommonConst.ErrorCode.ACCOUNT_SHUT_DOWN -> {//该账号已经被关小黑屋
                        val ext = JsonUtils.fromJson<UserNumberExt>(JsonUtils.toJson(it.ext))
                        Router.instance.setPath(RoutePath.SEAL_ACCOUNT_ACTIVITY)
                            .withLong("otherId", mOtherId)
                            .withLong("userId", ext?.userNumber ?: 0L)
                            .navigation(this)
                    }
                }
                finish()
            })
        }
        //关注
        mViewModel.followerLiveData.observe(this) { resultState ->
            parseState(resultState, {
                mOtherInfo?.relation?.followed = true
                mBinding.followImg.play()
                ToastGravity.showGravity(string.follower_succeed)
            }, {
                ToastGravity.showGravity(it.errorMsg)
            })
        }
        //点赞
        mViewModel.addLikeLiveData.observe(this) { resultState ->
            parseState(resultState, {
                mIsLiked = true

                mBinding.addLike.apply {
                    pause()
                    path = LIKE_AFTER_ANIM_PAG
                    setRepeatCount(1)
                    addListener(object : PAGListener {
                        override fun onAnimationEnd(p0: PAGImageView?) {
                            mBinding.addLike.post {
                                val scaleAnimator = ObjectAnimator.ofPropertyValuesHolder(
                                    mBinding.addLike,
                                    PropertyValuesHolder.ofFloat("scaleX", 1.0f, 0.0f, 0.0f),
                                    PropertyValuesHolder.ofFloat("scaleY", 1.0f, 0.0f, 0.0f)
                                )
                                scaleAnimator.interpolator = LinearInterpolator()
                                scaleAnimator.duration = 300L
                                scaleAnimator.start()
                            }
                            mBinding.llLike.postDelayed({
                                mBinding.llLike.visibility = View.VISIBLE
                                val scaleAnimator = ObjectAnimator.ofPropertyValuesHolder(
                                    mBinding.llLike,
                                    PropertyValuesHolder.ofFloat("scaleX", 0.0f, 1.0f, 1.0f),
                                    PropertyValuesHolder.ofFloat("scaleY", 0.0f, 1.0f, 1.0f)
                                )
                                scaleAnimator.addListener(onEnd = {
                                    mBinding.addLike.visibility = View.GONE
                                })
                                scaleAnimator.interpolator = LinearInterpolator()
                                scaleAnimator.duration = 500L
                                scaleAnimator.start()
                            }, 300)
                        }
                    })
                    play()
                }
                mBinding.likeNum.text = (mOtherInfo?.account?.likes?.plus(1)).toString()
            }, {
                ToastGravity.showGravity(it.errorMsg)
            })
        }
        //备注
        mViewModel.remarkLiveData.observe(this) {
            if (it.isEmpty()) {
                mBinding.selectRemark.text = getString(string.add_a_remark)
            } else {
                mBinding.selectRemark.text = it
                val otherInfo = mOtherInfo
                if (otherInfo != null) {
                    val remark = UserOtherRemarkVo(it)
                    mOtherInfo = otherInfo.copy(remark = remark).apply {
                        OtherUserCacheUtils.addUser(this)
                    }
                }
            }
        }

        if (!isSelf()) {
//            mUserStateProxy.observe {
//                mOtherInfo?.modifyState(it)
//                mUIProxy.updateUserState(it.state)
//            }
        }
    }

    override fun onResume() {
        super.onResume()
        if (mOtherInfo != null) {
            mViewModel.flushedInfoUser(mOtherId)
        }
        mBinding.contributorsView.update()
    }

    private fun isSelf(): Boolean {
        return mOtherId == UserManager.getUserId()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
            data?.let { result ->
                mOtherInfo?.let { otherInfo ->
                    val file = UriUtils.uri2File(UCrop.getOutput(result))
                    file?.let { uploadFile ->
                        mUIProxy.uploadPhoto(uploadFile.absolutePath, otherInfo)
                    }
                }
            }
        } else if (resultCode == RESULT_CANCELED && requestCode == UCrop.REQUEST_CROP) {
            mOtherInfo?.let {
                mUIProxy.againCamera()
            }
        }
    }
}